/**
 * 
 */
package com.massyframework.beanskin.launcher.scanning.maven;

import java.net.URL;
import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.massyframework.beanskin.ModuleIdentifier;

/**
 * {@link MavenProject}, Mave项目
 * @author huangkh
 *
 */
public abstract class MavenProject implements Comparable<MavenProject> {
	
	protected static Logger LOG = LoggerFactory.getLogger(MavenProject.class);
	private final Coordinate coordinate;

	/**
	 * 使用{@code builder}创建新实例
	 * @param {@link Builder}
	 */
	protected MavenProject(Builder builder) {
		this.coordinate = Objects.requireNonNull(
				builder.coordinate, "\"coordinate\" cannot be null.");
	}
	
	/**
	 * 坐标
	 * @return {@link Coordinate}
	 */
	public Coordinate getCoordinate() {
		return this.coordinate;
	}
	
	/**
	 * 输出文件，可以是jar文件，也可能是编译目录
	 * @return {@link URL}
	 */
	public abstract List<URL> getOutputFiles(ModuleIdentifier module);
	
	
		
	@Override
	public int compareTo(MavenProject o) {
		return this.coordinate.compareTo(o.coordinate);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((coordinate == null) ? 0 : coordinate.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MavenProject other = (MavenProject) obj;
		if (coordinate == null) {
			if (other.coordinate != null)
				return false;
		} else if (!coordinate.equals(other.coordinate))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("MavenProject [")
			.append("groupId=").append(this.coordinate.getGroupId()).append(",")
			.append("artifactId=").append(this.coordinate.getArtifactId()).append(",")
			.append("version=").append(this.coordinate.getVersion()).append("]");
		return builder.toString();
	}

	/**
	 * 构建器
	 */
	public static class Builder {
		
		private Coordinate coordinate;
    	    	
    	/**
    	 * 设置项目坐标
    	 * @param coordinate {@link Coordinate}
    	 * @return {@link Builder}
    	 */
    	public Builder coordinate(Coordinate coordinate) {
    		this.coordinate = coordinate;
    		return this;
    	}
    	
	}

}
